package screen;

import java.util.Vector;

import javax.microedition.lcdui.Graphics;

import utilities.GameResource;

import font.BitmapFont;

import model.Command;
import model.Item;
import main.GameCanvas;

public class QuestCompletedDlg extends Dialog{
	private String m_title;
	public int m_width, m_height, m_left, m_top;
	int m_bonusMoney1;
	int m_bonusMoney2;
	int m_bonusXp;
	Vector m_vtBonusItems;
	
	public void setCenterCmd(Command cmd){
		center = cmd;
	}
	
	public void show() {
		// TODO Auto-generated method stub
		GameCanvas.currentDialog = this;
	}

	public void setInfo(int questLevel, int bonusMoney1, int bonusMoney2, int bonusXp, Vector vtBonusItems) {
		m_title = GameResource.task + GameResource.space + questLevel + GameResource.finish;
		m_bonusMoney1 = bonusMoney1;
		m_bonusMoney2 = bonusMoney2;
		m_bonusXp = bonusXp;
		m_height = 120;
	
		m_vtBonusItems = vtBonusItems;
		
		if(m_vtBonusItems != null && m_vtBonusItems.size() > 0)
			m_height += 50;
		
		m_width = GameCanvas.w3d4;
		m_left = (GameCanvas.w - m_width) >> 1;
		m_top = (GameCanvas.h - m_height) >> 1;
	}
	
	public void paint(Graphics g){
		PaintPopup.paintBoxTab(g, null, m_left, m_top, m_width, m_height, 0x9be5ff, 0x3c8dc0);
		int tmp = m_top + 20;
		int x = m_left + (m_width >> 1);
		
		BitmapFont.drawBoldFont(g, m_title, x, tmp, 0x3a001e, Graphics.VCENTER | Graphics.HCENTER);
		
		tmp += 15;
		BitmapFont.drawBoldFont(g, GameResource.youReceived, x, tmp, 0xff3e45, Graphics.VCENTER | Graphics.HCENTER);
		
		tmp += 20;
		
		int w = m_left + 10;
		String str = GameResource.gold +":";
		BitmapFont.drawNormalFont(g, str, w, tmp, 0x3a001e, Graphics.LEFT);
		BitmapFont.drawBoldFont(g, m_bonusMoney1+"", w+BitmapFont.m_facedeFont.stringWidth(str), tmp, 0x3a001e, Graphics.LEFT);
		str = GameResource.gold +":" +m_bonusMoney1;
		
		BitmapFont.drawNormalFont(g, GameResource.space + GameResource.dina +":", w+BitmapFont.m_facedeFont.stringWidth(str), tmp, 0x3a001e, Graphics.LEFT);
		str = GameResource.gold +":" +m_bonusMoney1+GameResource.space + GameResource.dina +":";
		BitmapFont.drawBoldFont(g, ""+ m_bonusMoney2, w+BitmapFont.m_facedeFont.stringWidth(str), tmp, 0x3a001e, Graphics.LEFT);
		
		tmp += 15;
		BitmapFont.drawNormalFont(g, GameResource.exp +":", w, tmp, 0x3a001e, Graphics.LEFT);
		str = GameResource.exp+":";
		BitmapFont.drawBoldFont(g, m_bonusXp+"", w+BitmapFont.m_facedeFont.stringWidth(str), tmp, 0x3a001e, Graphics.LEFT);
		
		
		x = m_left + 15;
		tmp += 30;
		if(m_vtBonusItems != null){
			//paint gift
            int a = m_vtBonusItems.size();
			for(int i = 0; i < a; i++){
				Item item = (Item)m_vtBonusItems.elementAt(i);
				item.paintIcon(g, x, tmp);
				
				x += 15;
				str = GameResource.space + item.m_iNumItem;
				BitmapFont.drawBoldFont(g, str, x, tmp, 0x3a001e, Graphics.LEFT);
				x += BitmapFont.m_facedeFont.stringWidth(str) + 20;
			}	
		}				
				
		tmp = m_top + m_height - 20;
		BitmapFont.drawBoldFont(g, center.caption, GameCanvas.hw, tmp, 0x3a001e, Graphics.HCENTER);
	}
	
	public void update() {
		if(GameCanvas.isPointerClick){
			int ww=0;
			ww = BitmapFont.m_bmFont.stringWidth(center.caption)+17;
			
			int tmp = m_top + m_height - 20;
			if(center!=null&&GameCanvas.isPointer(GameCanvas.hw-ww/2, tmp, ww, 20)){
				center.action.perform();
			}
		}
		super.update();
	}
}
